﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace BattleThis.Core.Battle
{
	/// <summary>
	/// The Armor of a Unit.
	/// </summary>
	[System.Diagnostics.DebuggerDisplay( "Armor {Current}/{Orginal}" )]
	public class Armor
	{

		#region Variablen

		private const string PercentFormat = "{0}%";

		/// <summary>
		/// Definieds a emptry Armor.
		/// </summary>
		public readonly static Armor Empty = new Armor();

		#endregion

		#region Properties

		/// <summary>
		/// Gets or sets the current.
		/// </summary>
		/// <value>
		/// The current.
		/// </value>
		public int Current { get; set; }

		/// <summary>
		/// Gets or sets the orginal.
		/// </summary>
		/// <value>
		/// The orginal.
		/// </value>
		public int Orginal { get; protected set; }
		#endregion

		#region Methoden

		/// <summary>
		/// Initializes a new instance of the <see cref="Armor"/> class.
		/// </summary>
		protected Armor()
		{
			this.Current = 0;
			this.Orginal = 0;
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="Armor"/> class.
		/// </summary>
		/// <param name="orginal">The orginal.</param>
		public Armor( int orginal )
		{
			if( orginal <= 0 ) throw new ArgumentOutOfRangeException( "orginal <= 0" );

			this.Orginal = orginal;
			this.Current = orginal;
		}

		/// <summary>
		/// Determines whether this instance is destroyed.
		/// </summary>
		/// <returns>
		///   <c>true</c> if this instance is destroyed; otherwise, <c>false</c>.
		/// </returns>
		public bool IsDestroyed()
		{
			return this.Current <= 0;
		}

		/// <summary>
		/// Gets the percent value.
		/// </summary>
		/// <returns></returns>
		private int GetPercentValue()
		{
			int value = 0;
			if( !this.IsDestroyed() )
			{
				value = (int)( this.Current / ( this.Orginal * 0.01f ) );
			}
			return value;
		}

		/// <summary>
		/// Get the Armor in percent.
		/// </summary>
		/// <returns></returns>
		public string ToPercent()
		{
			int value = GetPercentValue();
			return string.Format( PercentFormat, value );
		}

		public string ToPercentDamaged()
		{
			int value = 100;
			if( !this.IsDestroyed() )
			{
				value = 100-  this.GetPercentValue();
			}

			return string.Format( PercentFormat, value );
		}

		#endregion
		
	}
}